from flask import Flask,request,session,current_app,g

app = Flask(__name__)
app.secret_key = "asfasfasfafsaf"

"""
working outside of request context 超出了请求上下文的范围
print(request)
print(session)


working outside of application context 超出了应用上下文的范围
print(current_app)
print(g)
"""

# 127.0.0.1:5000/ ---> 请求发送过来的时候才能去使用 request
@app.route('/')
def hello():
    # 请求上下文（request session）,保存了当前本次请求的相关数据
    # request封装HTTP请求的内容
    print(request.method)
    print(request.url)
    session['name']='asasgas'
    print(session.get('name'))

    # 应用上下文（current_app g）
    print(current_app.config.get('DEBUG'))

    # 不同用户使用线程id进行区分
    g.username = 'asfasa'
    print(g.username)

    return 'hello world'

if __name__ == '__main__':
    app.run(debug=True)
